IF OBJECT_ID('ssf.dpnd_get_referencing_object') IS NOT NULL
	DROP FUNCTION ssf.dpnd_get_referencing_object
GO

CREATE FUNCTION ssf.dpnd_get_referencing_object (
	@dpnd_object_name NVARCHAR(512)
)
RETURNS TABLE
AS
	RETURN (
		SELECT ssf.dpnd_get_header_object_name(header_object_id) AS referencing_dpnd_object_name
			, dpnd_object_name AS referenced_as
			, dependency_type
			, change_type
	FROM ssf.dpnd_dependency_object WITH (NOLOCK)
	WHERE dpnd_object_name = @dpnd_object_name
	OR CASE WHEN PARSENAME(dpnd_object_name, 2) IS NULL AND PARSENAME(dpnd_object_name, 4) IS NULL
		THEN ISNULL(PARSENAME(dpnd_object_name, 3) + '.', '')
			+ ISNULL(OBJECT_SCHEMA_NAME(OBJECT_ID(dpnd_object_name), DB_ID(ISNULL(PARSENAME(dpnd_object_name, 3), DB_NAME()))), 'ssf')
			+ '.' + PARSENAME(dpnd_object_name, 1)
		ELSE dpnd_object_name
		END = CASE WHEN PARSENAME(@dpnd_object_name, 2) IS NULL AND PARSENAME(@dpnd_object_name, 4) IS NULL
		THEN ISNULL(PARSENAME(@dpnd_object_name, 3) + '.', '')
			+ ISNULL(OBJECT_SCHEMA_NAME(OBJECT_ID(@dpnd_object_name), DB_ID(ISNULL(PARSENAME(@dpnd_object_name, 3), DB_NAME()))), 'ssf')
			+ '.' + PARSENAME(@dpnd_object_name, 1)
		ELSE @dpnd_object_name
		END
	)
GO
